package hz.mobileproject.pda.ui.adapter;

import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.entity.response.OddPostListBean;

/**
 * Created by zmybi on 2017/8/31.
 */

public class oddPostItemAdapter extends RecyclerView.Adapter<oddPostItemAdapter.MyViewHolder> {


    private final List<OddPostListBean> stringList;
    private final DelCallback delcallback;



    public oddPostItemAdapter(List<OddPostListBean> stringList, DelCallback delcallback) {
        this.stringList = stringList;
        this.delcallback = delcallback;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_adapter, parent, false);
        return new MyViewHolder(view);
    }


    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        OddPostListBean bean = stringList.get(position);
        holder.mPoliceName.setText(bean.report_police_name);
        holder.mDeptName.setText(bean.report_dept_name);
        holder.mTypeName.setText(bean.report_type_name);   //故障类别
        holder.mTime.setText(bean.report_time);  //时间
        holder.mFangshi.setText(bean.data_source_name);
        //TODO 可能为空串
        holder.mFaultGenreName.setText(bean.falut_genre_name);
        holder.mHandleDeptName.setText(bean.handle_dept_name);

        holder.mState.setText(bean.status_name);
        holder.mTitle.setText(bean.title);
        holder.mContent.setText(bean.content);

        //判断 如果status为1即待分配则显示删除按钮
        if(1 == bean.status) {
            holder.mBtDel.setVisibility(View.VISIBLE);
            holder.mBtDel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    delcallback.click(view, position, stringList);
                }
            });
        }else {
            holder.mBtDel.setVisibility(View.GONE);
        }




    }

    @Override
    public int getItemCount() {
        return stringList == null ? 0 : stringList.size();
    }


    static class MyViewHolder extends RecyclerView.ViewHolder {


//        @BindView(R.id.bt_del)
        Button mBtDel;
//        @BindView(R.id.police_name)
        TextView mPoliceName;
//        @BindView(R.id.dept_name)
        TextView mDeptName;
//        @BindView(R.id.type_name)
        TextView mTypeName;
//        @BindView(R.id.time)
        TextView mTime;
//        @BindView(R.id.fangshi)
        TextView mFangshi;
//        @BindView(R.id.fault_genre_name)
        TextView mFaultGenreName;
//        @BindView(R.id.handle_dept_name)
        TextView mHandleDeptName;
//        @BindView(R.id.state)
        TextView mState;
//        @BindView(R.id.title)
        TextView mTitle;
//        @BindView(R.id.content)
        TextView mContent;
//        @BindView(R.id.cardview)
        CardView mCardview;
//



        public MyViewHolder(View view) {
            super(view);
//            ButterKnife.bind(this,itemView);
            mBtDel = (Button) view.findViewById(R.id.bt_del);
            mPoliceName = (TextView) view.findViewById(R.id.police_name);
            mDeptName = (TextView) view.findViewById(R.id.dept_name);
            mTypeName = (TextView) view.findViewById(R.id.type_name);
            mTime = (TextView) view.findViewById(R.id.time);
            mFangshi = (TextView) view.findViewById(R.id.fangshi);
            mFaultGenreName = (TextView) view.findViewById(R.id.fault_genre_name);
            mHandleDeptName = (TextView) view.findViewById(R.id.handle_dept_name);
            mState = (TextView) view.findViewById(R.id.state);
            mTitle = (TextView) view.findViewById(R.id.title);
            mContent = (TextView) view.findViewById(R.id.content);
        }
    }


    /**
     * 25      * 自定义接口，用于回调按钮点击事件到Activity
     * 26      * @author Ivan Xu
     * 27      * 2014-11-26
     * 28
     */

    public interface DelCallback {
        void click(View v, int position, List<OddPostListBean> stringList);
    }

}
